/**
 * Copyright 2008 by Robert Konigsberg
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the same terms as Perl.
 *
 * @see http://www.perl.com/perl/misc/Artistic.html
 */
package visitor.maze;

import org.testng.annotations.Test;

@Test
public class RoomTest {

  @Test
  public void testRoomId() {
    assert new Room(1).getId() == 1;
    assert new Room(3).getId() == 3;
  }

  @Test
  public void connectRooms() {
    Room room1 = new Room(1);
    Room room2 = new Room(2);

    assert room1.getExits().size() == 0;
    assert room2.getExits().size() == 0;

    room1.setExit(Direction.NORTH, room2);
    assert room1.getExits().size() == 1;
    assert room2.getExits().size() == 0;
    assert room1.getExits().iterator().next() == Direction.NORTH;
    assert room1.getExit(Direction.NORTH) == room2;
    assert room1.getExit(Direction.SOUTH) == null;
    assert room1.getExit(Direction.EAST) == null;
    assert room1.getExit(Direction.WEST) == null;
  }

  @Test(expectedExceptions=IllegalArgumentException.class) 
  public void tryToReconnectToTheSameDirectionTwice() {
    Room room1 = new Room(1);
    Room room2 = new Room(2);
    Room room3 = new Room(3);
    room1.setExit(Direction.WEST, room2);
    room1.setExit(Direction.WEST, room3);
  }

  @Test
  public void testHashCodeAndEquals() {
    Room room1 = new Room(1);
    Room room2 = new Room(2);
    Room room1a = new Room (1);

    assert room1.equals(room1a);
    assert room1a.equals(room1);
    assert !room2.equals(room1);
    assert !room2.equals(room1a);
    assert !room1.equals(room2);
    assert !room1a.equals(room2);

    assert room1.hashCode() == room1a.hashCode();
    assert room1a.hashCode() == room1.hashCode();
    assert room2.hashCode() != room1.hashCode();
    assert room2.hashCode() != room1a.hashCode();
    assert room1.hashCode() != room2.hashCode();
    assert room1a.hashCode() != room2.hashCode();
  }
}
